package com.skycong.hello77.activity.fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.skycong.hello77.R;
import com.skycong.hello77.fragment.GetValueFrament;

/**
 * @author ruanmingcong
 * @date 2018/1/20 17:25
 */
public class GetValueFraActivity extends FragmentActivity implements View.OnClickListener{
    private FragmentTransaction transaction;
    private FragmentManager manager;
    private EditText edt;
    private Button btn;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_getvalue);


        manager =getSupportFragmentManager();
        transaction = manager.beginTransaction();
        transaction.add(R.id.layout_value,new GetValueFrament());
        transaction.commit();
        edt = (EditText) findViewById(R.id.getvalue);
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        String content = edt.getText().toString().trim();
        //传递数据,创造bundle对象,将需要传递的数据传递给Bundle中，调用frament的setArguments（）方法
        GetValueFrament myFrament = new GetValueFrament();
        Bundle bundle = new Bundle();
        bundle.putString("content",content);
        myFrament.setArguments(bundle);
         //将有数据的Frament替换没有数据的
        manager = getSupportFragmentManager();
        transaction = manager.beginTransaction();
        transaction.replace(R.id.layout_value,new GetValueFrament());
        transaction.commit();
    }
}
